package org.shs.company.dao;

import java.util.ArrayList;

import org.shs.common.dao.IBaseDAO;
import org.shs.common.utils.DataHolder;
import org.shs.company.form.CompanyForm;
import org.shs.company.model.CompanyModel;
import org.shs.worker.model.WorkerModel;

/**
 * Interface specifying the data access methods related to the Company module.
 * <br/>
 * <br/><b>Created:</b>&nbsp;&nbsp; Dec 23, 2008 1:26:18 AM
 *
 * @author Gunjan
 */
public interface ICompanyDAO extends IBaseDAO
{

   /**
    * Retrieves the list of companies and related information. This can also 
    * be a list of companies based upon a search performed on the company name.
    * @param cmpnyData Encapsulates the partial company name and the inactive
    * company search flag
    * @return The list of all companies.
    * @throws Exception Thrown if query resulted in an error.
    */
   public ArrayList<CompanyModel> getCompanies(DataHolder cmpnyData) 
   throws Exception;
   
   /**
    * Retrieves the details for a particular company.
    * @param companyId The company ID whose details are to be fetched.
    * @return The model encapsulating all details about the company.
    * @throws Exception Thrown if query resulted in an error.
    */
   public CompanyModel getCompanyDetails(String companyId) 
   throws Exception;

   /**
    * Inserts details for a new company.
    * @param companyData Details for the new company.
    * @return Generated ID of the new company.
    * @throws Exception Thrown if query resulted in an error.
    */
   public String addNewCompanyData(CompanyForm companyData) throws Exception;

   /**
    * Updates the details for an existing company.
    * @param companyData Updated details of the company to be modified.
    * @throws Exception Thrown if query resulted in an error.
    */
   public void editCompanyData(CompanyForm companyData) throws Exception;

   /**
    * Updates the 'active' flag for an existing company.
    * @param companyData Model containing the 'active' status and the company ID
    * for which the flag is to be updated.
    * @throws Exception Thrown if query resulted in an error.
    */
   public void updActiveStatus(DataHolder companyActvData) throws Exception;
   
   // ==========================================================================
   // Following properties relate to worker-company association.
   // ==========================================================================
   
   /**
    * Retrieves a list of all workers associated with the given company.
    * @param companyData Model containing the company ID for which all
    * associated workers are to be retrieved. It also specifies the worker type
    * (supervisor or labour) which is to be fetched. 
    * @return List of all workers of the given type associated with the given
    * company.
    * @throws Exception Thrown if query resulted in an error.
    */
   public ArrayList<WorkerModel> getWorkersForCompany(WorkerModel companyData)
   throws Exception;
   
   /**
    * Gets the companies associated with the given worker.
    * @param workerId The worker whose associated companies are to be fetched.
    * @return List of companies associated with the given worker.
    * @throws Exception Thrown if query resulted in an error.
    */
   public ArrayList<CompanyModel> getCompaniesForWorker(String workerId)
   throws Exception;
   
   /**
    * Adds a new company-worker association information.
    * @param workerData Model containing the worker and associated company IDs
    * for which the worker-company association is to be added.
    * @return Auto-generated unique ID of the new worker-company association.
    * @throws Exception Thrown if query resulted in an error.
    */
   public String addNewCompanyWorkerAssoc(WorkerModel workerData) throws Exception;
   
   /**
    * Deletes the given company-worker association.
    * @param companyWorkerAssocId The unique ID identifying the company-worker
    * association to be deleted.
    * @throws Exception Thrown if query resulted in an error.
    */
   public void delCompanyWorkerAssoc(String companyWorkerAssocId) throws Exception;
   
   /**
    * Deletes all company-worker associations for the given worker.
    * @param workerId The worker for which all worker-company associations are
    * to be deleted.
    * @throws Exception Thrown if query resulted in an error.
    */
   public void delAllAssocForWorker(String workerId) throws Exception;
   
}